'''
Created on 2011-04-08

@author: jasisz
'''
from PyQt4 import QtGui, QtCore

class BoardView(QtGui.QGraphicsView):
    def __init__(self, parent=None, origPixmap=None):
        """
        QGraphicsView that will show an image scaled to the current widget size
        using events
        """
        super(BoardView, self).__init__(parent)
        self.origPixmap = origPixmap
        self.scene = QtGui.QGraphicsScene()
        self.setScene(self.scene)
        
    def resizeEvent(self, event):
        """
        Handle the resize event.
        """
        if self.origPixmap == None:
            return
        
        pixmap = self.origPixmap      
        size = event.size()
        pixmap = pixmap.scaled(size, QtCore.Qt.IgnoreAspectRatio, QtCore.Qt.SmoothTransformation)
        
        if len(self.items()) == 0:
            self.scene.addPixmap(pixmap)
                 
        item = self.items()[0]
        item.setPixmap(pixmap)
        
    def setBackground(self, pixmap):
        self.origPixmap = pixmap
        self.setFixedSize(pixmap.size())
        
        